package me.heyclock.hl.recordwriter.robot;

import android.app.Activity;
import android.util.Log;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
 * @des Activity管理栈
 * @author  hl
 * @date 2018.06.08
 */
public class ActivityStack {
    private static Stack<Activity> activityStack = new Stack<>();
    private static Map<String, String> actMessageMap = new HashMap<String, String>(){
        {
            put("app.HomeActivity", "当前是主界面");
            put("activity.LoginActivity", "当前在登录页面了");
        }
    };

    public static void addActivity(Activity activity){
        activityStack.push(activity);
    }

    public static Activity removeActivty(){
        return activityStack.pop();
    }

    /**
     * 获取栈顶页面
     * @return
     */
    public static Activity getActivty(){
        if (activityStack.size() > 0){
            return activityStack.get(activityStack.size() - 1);
        }
        return null;
    }

    /**
     * 获取当前页面类名称
     * @return
     */
    public static String getCurActClassName(){
        if (!activityStack.empty()){
            Activity activity = activityStack.get(activityStack.size() - 1);
            return activity.getLocalClassName();
        }
        return "";
    }

    /**
     * 获取当前页面播放文本消息
     * @return
     */
    public static String getCurActMessage(){
        if (!activityStack.empty()){
            Activity activity = activityStack.get(activityStack.size() - 1);
            if (actMessageMap.containsKey(activity.getLocalClassName())){
                return actMessageMap.get(activity.getLocalClassName());
            }
        }
        return "";
    }
}
